package com.example.canvastest;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by 700 on 2018/7/30.
 */

public class DrawPoint extends View{

    private Paint paint;
    private float[] points = new float[]{10.0f,10.0f,  20.0f,60.0f,  60.0f,60.0f,  70.0f,10.0f,
                                            100.0f,10.0f,  130.0f,10.0f,  160.0f,10.0f};

    public DrawPoint(Context context, AttributeSet attrs,
                        int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public DrawPoint(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public DrawPoint(Context context) {
        super(context);
    }

     private void initView(){
         paint = new Paint();
         paint.setColor(getResources().getColor(
                 android.R.color.holo_blue_light
         ));
         paint.setAntiAlias(true);
         paint.setStrokeWidth(10.0f);        //呵呵哒，没线宽不给显示←_←,现况太小也看不到←_←，坑了我半天
     }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        initView();
//        canvas.drawColor(Color.WHITE);                  //白色背景
        canvas.drawColor(getResources().getColor(
                android.R.color.holo_orange_light
        ));
        canvas.drawPoints(points,paint);//用法自看源码

    }
}
